<?php

class Sub_account_permission extends CI_Controller {
	
	function __construct() {
		parent::__construct();
		$this->load->model('F-MODEL/model_employers');
		if($this->model_employers->is_logined()){
			$author_id=$this->session->userdata('employer_active_access');
			$main_modules = $this -> model_globals -> select_all('employer_main_modules') -> result();
			
			foreach ($main_modules as $main_module) {
				$main_module_id = $main_module -> employer_main_module_id;
				$name = $main_module -> name;

				$sub_modules = $this -> model_globals -> select_join('employer_module_permissions', array('employer_modules' => array('using_employer_module_id' => 'employer_module_id')), 'inner', array('using_employer_main_module_id' => $main_module_id, 'using_employer_id' => $author_id));

				foreach ($sub_modules->result() as $sub_module) {
					$module_permission_id = $sub_module -> employer_module_permissions_id;
					$sub_name = $sub_module -> description;
					$is_access = $sub_module -> is_access;
					//$is_checked = ($is_access == "YES") ? "checked" : '';
				
					if ((str_replace('-','_', $this->uri->segment(2))==$sub_name)) {
					
						if($is_access!='YES'){
							redirect('employers/no-permission');
						}
					} 
					
				}

			}
			
		}
	}
	public function error_404(){
		
		$data['title']="Error 404";
		$data['locations']=$this->model_globals->select_all('job_locations');
		$categories=$this->model_globals->select_all('job_categories')->result();
			$option="";
			foreach($categories as  $category){
				$category_id=$category->job_category_id;
				$name=$category->name;
				$option.='<optgroup label="'.$name.'">';
				$sub_categories=$this->model_globals->select_where('job_sub_categories',array('using_job_category_id'=>$category_id))->result();
				foreach($sub_categories as $sub_category){
					$sub_category_id=$sub_category->job_sub_category_id;
					$sub_name=$sub_category->name;
					$option.='<option value="'.$category_id.'-'.$sub_category_id.'">'.$sub_name.'</option>';
				}
				$option.='</optgroup>';
			}
		$data['categories']=$option;
		$data['error_404']="Error 404";
		$this->load->view(F_MASTER."index",$data);
	}
}
